<?php
// +-----------------------------------------------
// | Name：星空框架  运费计算服务
// +-----------------------------------------------
// | Version: V5.0
// +-----------------------------------------------
// | Author: xkyinzhe <zhonghuaxinxing@sina.cn>
// +-----------------------------------------------
// | Time: 2021-05-11 09:59
// +-----------------------------------------------
declare(strict_types=1);

namespace app\common\services;


use app\common\model\ShippingTemplate as ShippingTemplateMode;

/**
 * @xk 运费计算服务
 */
class ShippingServices
{
  public static function getCostPrice($address,$store_id,$all_count){
    $shippingTemplateMode = new ShippingTemplateMode();
    $province = $address['province']; // 获取城市代码
    $cost_price = 0;
    $cost_type = 0;
    if($store_id > 0){
      // 开始 获取  该店铺下 当前收货城市是否存在配送规则
      $template_info = $shippingTemplateMode
      ->where([['store_id','=',$store_id],['area_show','like','%'.$province.'%']])
      ->field('`price`,`price_type`')
      ->find();
      if($template_info){
        switch ($template_info['price_type']) {
          case '1':
            $cost_price = $template_info['price']*$all_count;
            $cost_type = $template_info['price_type'];
            break;
          case '2':
            $cost_price = $template_info['price'];
            $cost_type = $template_info['price_type'];
            break;
        }
      }
    }
    return ['cost_price'=>$cost_price,'cost_type'=>$cost_type];

  }

}
